The present invention relates to a portable electronic apparatus which is called an IC card and incorporates an IC (integrated circuit) having, e.g., a nonvolatile data memory and a control element such as a CPU (central processing unit).
Recently, IC cards incorporating IC chips having nonvolatile data memories and control elements such as CPUs have begun to prevail as a new portable data storage medium. The data stored in the data memory incorporated in such an IC card is managed by an internal control element or an external unit.
As a method to access such an IC card, a random access is performed wherein the data memory is divided into a plurality of areas and the respective areas are accessed. In this case, specific data such as a start address of the target area and the number of bytes constituting the area is registered in the IC card. When the target area data is added to input instruction data, the specific data of the target area in the IC card is searched, converted into physical access data, and processed.
Generally, in order to increase the reliability of data stored in an IC card, when data is to be stored, specific information for identifying whether the data is valid or not is added to the data and the data is stored. If some abnormality occurs during data writing, this information is used in the subsequent data readout to determine that this data is abnormal. When the data is to be read out, whether the data is valid or not is determined in accordance with the specific information, and the determination result is added when the data is output to an external unit.
Conventionally, single response data is output in response to a single instruction data. When the response data is to be output, a code indicating the processing result in the IC card is added. The determination result regarding whether the data is valid or not, which is obtained upon the preceding data readout, is also converted into a code and output. However, when a data string has such a data length that the data string cannot be output by a single transmission, at a time of completion of data string output, the code is added to the data string and the data string is output.
In this manner, conventionally, when a data string having such a data length that the data string cannot be output by a single transmission is read out, a code indicating the validity of the data string is output only in the final transmission, and an external unit cannot determine the validity of the data until the final transmission.
When data is determined to be abnormal at the time it is written and when a write sequence for invalidating this data is set, for example, when a power source voltage supplied to an IC card is momentarily cut off, control of a control element is disabled, and data being written cannot be invalidated. As a result, reliability as an IC system is degraded.